package com.huaxinkai.service.impl;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.huaxinkai.entity.BaseEntity;
import com.huaxinkai.service.IBaseService;

/**
 * Created by liuzh on 2017/5/6.
 */
@Service
@Transactional
@Scope("prototype")
@SuppressWarnings({"rawtypes"})
public class BaseService implements IBaseService{
	
	@Resource
	protected SessionFactory seesionFactory;
	protected Session session;
	protected Transaction transaction;
	
	
	public SessionFactory getSeesionFactory() {
		return seesionFactory;
	}
	public void setSeesionFactory(SessionFactory seesionFactory) {
		this.seesionFactory = seesionFactory;
	}
	public void getCurrentSession() {
		session = seesionFactory.getCurrentSession();
	}
	public Session getSession() {
		return session;
	}
	public void setSession(Session session) {
		this.session = session;
	}
	public Transaction getTransaction() {
		return transaction;
	}
	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;
	}
	@Override
	public List queryHQL(String hql){
		return session.createQuery(hql).list();
	}
	@Override
	public List querySQL(String sql){
		return session.createSQLQuery(sql).list();
	}
	
	/*查询方法*/
	
	

	public boolean update(int id, String column, String val, String tablename) throws Exception {
		String sql = String.format("UPDATE %s SET %s = '%s' WHERE id = %d", tablename, column, val, id);
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean update(int id, Map keyAndVal, String tablename) throws Exception {
		String setsql = "";
		for (Object key : keyAndVal.keySet()) {
			if (setsql != "") {
				setsql += ",";
			}
			setsql += String.format(" %s = '%s' ", key, keyAndVal.get(key));
		}
		String sql = String.format("UPDATE %s SET %s WHERE id = %d", tablename, setsql, id);
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean update(String sql) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean update(String sql, Object... params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				sqlQuery.setParameter(i, params[i]);
			}
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean update(String sql, Map<String, Object> params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		return sqlQuery.setProperties(params).executeUpdate() > 0;
	}

	/**
	 * 添加方法
	 */
	public boolean insert(BaseEntity entity) throws Exception {
		session.save(entity);
		return true;
	}

	public boolean delete(BaseEntity entity) throws Exception {
		session.delete(entity);
		return true;
	}

	public boolean update(BaseEntity entity) throws Exception {
		session.update(entity);
		return true;
	}

	public Object selectOne(String sql) throws Exception {
		return session.createQuery(sql).uniqueResult();
	}

	public Object selectOne(Class clazz, int id) throws Exception {
		return session.get(clazz, id);
	}

	public Object selectOne(Class clazz, String column, Object value) throws Exception {
		String hql = String.format("FROM %s WHERE " + column + "=" + value, clazz.getSimpleName());
		return session.createQuery(hql).uniqueResult();
	}

	public List query(Class clazz, String column, Object value) throws Exception {
		String hql = String.format("FROM %s WHERE " + column + "=" + value, clazz.getSimpleName());
		return session.createQuery(hql).list();
	}

	public List query(Class clazz, String[] column, Object[] value) throws Exception {
		String hql = String.format("FROM %s WHERE 1 = 1 ", clazz.getSimpleName());
		for (int i = 0; i < column.length; i++) {
			hql += " AND " + column[i] + "=" + value[i];
		}
		return session.createQuery(hql).list();
	}

	public Object selectOne(String hql, Object... params) throws Exception {
		Query query = session.createQuery(hql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				query.setParameter(i, params[i]);
			}
		}
		return query.uniqueResult();
	}

	public Object selectOne(String hql, Map<String, Object> params) throws Exception {
		return session.createQuery(hql).setProperties(params).uniqueResult();
	}

	public Object selectSqlOne(String sql) throws Exception {
		return session.createSQLQuery(sql).uniqueResult();
	}

	public Object selectSqlOne(String sql, Map<String, Object> params) throws Exception {
		return session.createSQLQuery(sql).setProperties(params).uniqueResult();
	}

	public Object selectSqlOne(String sql, Object... params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				sqlQuery.setParameter(i, params[i]);
			}
		}
		return sqlQuery.uniqueResult();
	}

	public List select(String hql) throws Exception {
		return session.createQuery(hql).list();
	}

	public List select(Class clazz) throws Exception {
		return session.createQuery("from " + clazz.getSimpleName()).list();
	}

	public List select(Class clazz, Integer... ids) throws Exception {
		return session.createQuery("from " + clazz.getSimpleName() + " where id in(:ids) ").setParameterList("ids", ids).list();
	}

	public List select(Class clazz, int page, int rows) throws Exception {
		return session.createQuery("from " + clazz.getSimpleName()).setFirstResult((page - 1) * rows).setMaxResults(rows).list();
	}

	public List select(String hql, Object... params) throws Exception {
		Query query = session.createQuery(hql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				query.setParameter(i, params[i]);
			}
		}
		return query.list();
	}

	public List select(String hql, Map<String, Object> params) throws Exception {
		return session.createQuery(hql).setProperties(params).list();
	}

	public List select(String hql, int page, int rows, Object... params) throws Exception {
		Query query = session.createQuery(hql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				query.setParameter(i, params[i]);
			}
		}
		return query.setFirstResult((page - 1) * rows).setMaxResults(rows).list();
	}

	public List select(String hql, Map<String, Object> params, int page, int rows) throws Exception {
		return session.createQuery(hql).setProperties(params).setFirstResult((page - 1) * rows).setMaxResults(rows).list();
	}

	public long selectCount(Class clazz) throws Exception {
		return (Long) session.createQuery("select COUNT(*) from " + clazz.getSimpleName()).uniqueResult();
	}

	public long selectCount(String hql, Object... params) throws Exception {
		Query query = session.createQuery(hql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				query.setParameter(i, params[i]);
			}
		}
		return (Long) query.uniqueResult();
	}

	public long selectCount(String hql, Map<String, Object> params) throws Exception {
		return (Long) session.createQuery(hql).setProperties(params).uniqueResult();
	}

	public List selectSql(String sql) throws Exception {
		return session.createSQLQuery(sql).list();
	}

	public List selectSql(String sql, int page, int rows) throws Exception {
		return session.createSQLQuery(sql).setFirstResult((page - 1) * rows).setMaxResults(rows).list();
	}

	public List selectSql(String sql, Object... params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		if (null != params) {
			for (int i = 0; i < params.length; i++) {
				sqlQuery.setParameter(i, params[i]);
			}
		}
		return sqlQuery.list();
	}

	public List selectSql(String sql, Map<String, Object> params) throws Exception {
		List list = null;
		try {
			list = session.createSQLQuery(sql).setProperties(params).list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public List selectSql(String sql, int page, int rows, Object... params) throws Exception {
		List list = null;
		try {
			SQLQuery sqlQuery = session.createSQLQuery(sql);
			if (null != params) {
				for (int i = 0; i < params.length; i++) {
					sqlQuery.setParameter(i, params[i]);
				}
			}
			list = sqlQuery.setFirstResult((page - 1) * rows).setMaxResults(rows).list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public List selectSql(String sql, Map<String, Object> params, int page, int rows) throws Exception {
		List list = null;
		try {
			list = session.createSQLQuery(sql).setProperties(params).setFirstResult((page - 1) * rows).setMaxResults(rows).list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public boolean delete(int id, String tableName) throws Exception {
		boolean b = false;
		try {
			int rows = session.createSQLQuery("DELETE FROM " + tableName + " WHERE ID = " + id).executeUpdate();
			b = rows > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return b;
	}

	public boolean delete(int id, String tableName, String pkName) throws Exception {
		boolean b = false;
		try {
			int rows = session.createSQLQuery("DELETE FROM " + tableName + " WHERE " + pkName + " = " + id).executeUpdate();
			b = rows > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return b;
	}

	public boolean delete(Integer id, String tableName) throws Exception {
		boolean b = false;
		try {
			int rows = session.createSQLQuery("DELETE FROM " + tableName + " WHERE ID = " + id).executeUpdate();
			b = rows > 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return b;
	}

	public boolean delete(Integer id, String tableName, String pkName) throws Exception {
		return session.createSQLQuery("DELETE FROM " + tableName + " WHERE " + pkName + " = " + id).executeUpdate() > 0;
	}

	public boolean delete(String tableName, Integer... ids) throws Exception {
		String idString = "";
		for (int i = 0; i < ids.length; i++) {
			if (idString != "")
				idString += ",";
			idString += ids[i];
		}
		String sql = String.format("DELETE FROM %s WHERE ID IN(%s)", tableName, idString);
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String tableName, String pkName, Integer... ids) throws Exception {
		String idString = "";
		for (int i = 0; i < ids.length; i++) {
			if (idString != "")
				idString += ",";
			idString += ids[i];
		}
		String sql = String.format("DELETE FROM %s WHERE %s IN(%s)", tableName, pkName, idString);
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String id, String tableName) throws Exception {
		return session.createSQLQuery(String.format("DELETE FROM %s WHERE ID = '%s'", tableName, id)).executeUpdate() > 0;
	}

	public boolean delete(String id, String tableName, String pkName) throws Exception {
		return session.createSQLQuery(String.format("DELETE FROM %s WHERE %s = '%s'", tableName, pkName, id)).executeUpdate() > 0;
	}

	public boolean delete(String tableName, String... ids) throws Exception {
		String idString = "";
		for (int i = 0; i < ids.length; i++) {
			if (idString != "")
				idString += ",";
			idString += "'" + ids[i] + "'";
		}
		String sql = String.format("DELETE FROM %s WHERE ID IN(%s)", tableName, idString);
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String tableName, String pkName, String... ids) throws Exception {
		String idString = "";
		for (int i = 0; i < ids.length; i++) {
			if (idString != "")
				idString += ",";
			idString += "'" + ids[i] + "'";
		}
		String sql = String.format("DELETE FROM %s WHERE %s IN(%s)", tableName, pkName, idString);
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String sql) throws Exception {
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String sql, Object... params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		for (int i = 0; i < params.length; i++) {
			sqlQuery.setParameter(i, params[i]);
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean delete(String sql, Map<String, Object> params) throws Exception {
		return session.createSQLQuery(sql).setProperties(params).executeUpdate() > 0;
	}

	public boolean delete(String... sqls) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean delete(String[] sqls, Object... params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		for (int i = 0; i < params.length; i++) {
			sqlQuery.setParameter(i, params[i]);
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean delete(String[] sqls, Map<String, Object> params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).setProperties(params).executeUpdate() > 0;
	}

	public boolean delete(List<BaseEntity> entities) throws Exception {
		for (Object entity : entities) {
			session.delete(entity);
		}
		return true;
	}

	public boolean insert(List<BaseEntity> entities) throws Exception {
		for (Object entity : entities) {
			session.save(entity);
		}
		return true;
	}

	public boolean insert(String sql) throws Exception {
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean insert(String sql, Object... params) throws Exception {
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		for (int i = 0; i < params.length; i++) {
			sqlQuery.setParameter(i, params[i]);
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean insert(String sql, Map<String, Object> params) throws Exception {
		return session.createSQLQuery(sql).setProperties(params).executeUpdate() > 0;
	}

	public boolean insert(String... sqls) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean insert(String[] sqls, Object... params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		for (int i = 0; i < params.length; i++) {
			sqlQuery.setParameter(i, params[i]);
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean insert(String[] sqls, Map<String, Object> params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).setProperties(params).executeUpdate() > 0;
	}

	public boolean update(List<BaseEntity> entities) throws Exception {
		for (Object entity : entities) {
			session.update(entity);
		}
		return true;
	}

	public boolean update(String... sqls) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).executeUpdate() > 0;
	}

	public boolean update(String[] sqls, Object... params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		SQLQuery sqlQuery = session.createSQLQuery(sql);
		for (int i = 0; i < params.length; i++) {
			sqlQuery.setParameter(i, params[i]);
		}
		return sqlQuery.executeUpdate() > 0;
	}

	public boolean update(String[] sqls, Map<String, Object> params) throws Exception {
		String sql = "";
		for (int i = 0; i < sqls.length; i++) {
			if (i == sqls.length - 1) {
				sql += sqls[i];
			} else {
				sql += sqls[i] + ";";
			}
		}
		return session.createSQLQuery(sql).setProperties(params).executeUpdate() > 0;
	}

	@SuppressWarnings("unused")
	@Override
	public boolean insert(String tableName, Integer[] appendChar, Object[] columns, Object[]... values) throws Exception {
		if (null == tableName || tableName.isEmpty()) {
			return false;
		}

		if (null == columns) {
			return false;
		}

		if (null == values) {
			return false;
		}

		if (columns.length != values.length) {
			return false;
		}

		String appendCharStr = "";
		if (null != appendChar && appendChar.length > 0) {
			for (int i = 0; i < appendChar.length; i++) {
				appendCharStr += "|" + appendChar[i];
			}
		}
		appendCharStr += "|";

		String sql = "INSERT INTO %s(%s) VALUES %s";
		String columnSql = "";
		for (int i = 0; i < columns.length; i++) {
			if (!columnSql.isEmpty())
				columnSql += ",";
			columnSql += String.valueOf(columns[i]);
		}
		String valueSql = "";
		int index = 0;
		int length = values[0].length;
		for (int i = 0; i < values[0].length; i++) {
			if (!valueSql.isEmpty())
				valueSql += ",";
			String innerSql = "";
			for (int j = 0; j < values.length; j++) {
				if (!innerSql.isEmpty())
					innerSql += ",";
				String s = String.valueOf(values[j][i]);
				do {
					if (appendCharStr.contains("|" + j + "|")) {
						innerSql += "'" + s + "'";
						break;
					}
					innerSql += "'" + s + "'";
					break;
				} while (false);
			}
			valueSql += String.format("(%s)", innerSql);
		}
		return update(String.format(sql, tableName, columnSql, valueSql));
	}

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		String tableName = "";
		Object[] columns = { "ID", "NAME", "CODE" };
		Integer[] appendChar = { 0, 1, 2 };
		String appendCharStr = "";
		Object[] arr1 = { 1, 2, 3 };
		Object[] arr2 = { "1", "2", "3" };
		Object[] arr3 = { "001", "002", "003" };
		Object[][] values = { arr1, arr2, arr3 };
		if (null != appendChar && appendChar.length > 0) {
			for (int i = 0; i < appendChar.length; i++) {
				appendCharStr += "|" + appendChar[i];
			}
		}
		appendCharStr += "|";

		String sql = "INSERT INTO %s(%s) VALUES %s";
		String columnSql = "";
		for (int i = 0; i < columns.length; i++) {
			if (!columnSql.isEmpty())
				columnSql += ",";
			columnSql += String.valueOf(columns[i]);
		}
		String valueSql = "";
		int index = 0;
		int length = values[0].length;
		for (int i = 0; i < values[0].length; i++) {
			if (!valueSql.isEmpty())
				valueSql += ",";
			String innerSql = "";
			for (int j = 0; j < values.length; j++) {
				if (!innerSql.isEmpty())
					innerSql += ",";
				String s = String.valueOf(values[j][i]);
				do {
					if (appendCharStr.contains("" + j + "|")) {
						innerSql += "'" + s + "'";
						break;
					}

					try {
						innerSql += Float.parseFloat(s);
						break;
					} catch (Exception e) {

						try {
							innerSql += Integer.parseInt(s);
							break;
						} catch (Exception e2) {

							innerSql += "'" + s + "'";
							break;

						}
					}

				} while (false);
			}
			valueSql += String.format("(%s)", innerSql);
		}
		System.out.println(String.format(sql, tableName, columnSql, valueSql));
	}
	@Override
	public boolean delete(Integer[] ids, String tableName) throws Exception {
		return delete(tableName, ids);
	}
	@Override
	public boolean delete(String tableName, String pkName, String appendSql, Integer... ids) throws Exception {
		appendSql = null == appendSql ? "" : appendSql;
		String idString = "";
		for (int i = 0; i < ids.length; i++) {
			if (idString != "")
				idString += ",";
			idString += ids[i];
		}
		String sql = String.format("DELETE FROM %s WHERE %s IN(%s) %s", tableName, pkName, idString, appendSql);
		return update(sql);
	}
	@Override
	public boolean delete(Integer[] id, String pkName, String tableName) throws Exception {
		return delete(tableName, pkName, id);
	}
	@Override
	public int queryCount(Class clazz, int rows) throws Exception {
		long l = selectCount(clazz);
		int pages = 0;
		if (l == 0) {
			pages = 0;
		} else {
			pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
		}
		return pages;
	}
	@Override
	public int queryCount(String hql, int rows) throws Exception {
		long l = selectCount(hql, new Object[0]);
		int pages = 0;
		if (l == 0) {
			pages = 0;
		} else {
			pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
		}
		return pages;
	}
	@Override
	public int queryCount(String hql, int rows, Object... params) throws Exception {
		long l = selectCount(hql, params);
		int pages = 0;
		if (l == 0) {
			pages = 0;
		} else {
			pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
		}
		return pages;
	}
	@Override
	public int queryCount(String hql, Object[] objects) throws Exception {
		int l = (int) selectCount(hql, objects);
		return l;
	}
	@Override
	public int queryCount(String hql, Object[] params, int rows) throws Exception {
		long l = selectCount(hql, params);
		int pages = 0;
		if (l == 0) {
			pages = 0;
		} else {
			pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
		}
		return pages;
	}
	@Override
	public int queryCount(String hql, Map<String, Object> params, int rows) throws Exception {
		BigInteger b = (BigInteger) selectSqlOne(hql, params);
		int l = 0;
		if (b != null)
			l = b.intValue();
		int pages = 0;
		if (l == 0) {
			pages = 0;
		} else {
			pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
		}
		return pages;
	}
	@Override
	public int querySqlCount(String sql, Object[] params, int rows) throws Exception {
		Object obj = selectSqlOne(sql, params);
		if (obj instanceof Number) {
			long l = ((Number) obj).longValue();
			int pages = 0;
			if (l == 0) {
				pages = 0;
			} else {
				pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
			}
			return pages;
		}
		return 0;
	}
	@Override
	public int querySqlCount(String sql, Map<String, Object> params, int rows) throws Exception {
		Object obj = selectSqlOne(sql, params);
		if (obj instanceof Number) {
			long l = ((Number) obj).longValue();
			int pages = 0;
			if (l == 0) {
				pages = 0;
			} else {
				pages = (int) (l % rows == 0 ? l / rows : l / rows + 1);
			}
			return pages;
		}
		return 0;
	}
	@Override
	public Object query(Class clazz, int id) throws Exception {
		return selectOne(clazz, id);
	}
	@Override
	public Object queryOne(Class clazz, String column, Object value) throws Exception {
		return selectOne(clazz, column, value);
	}
	@Override
	public Object queryOne(String hql) throws Exception {
		return selectOne(hql);
	}
	@Override
	public Object queryOne(String hql, Object... params) throws Exception {
		return selectOne(hql, params);
	}
	@Override
	public Object queryOne(String hql, Map<String, Object> params) throws Exception {
		return selectOne(hql, params);
	}
	@Override
	public Object querySqlOne(String sql) throws Exception {
		return selectSqlOne(sql);
	}
	@Override
	public Object querySqlOne(String sql, Object... params) throws Exception {
		return selectSqlOne(sql, params);
	}
	@Override
	public Object querySqlOne(String sql, Map<String, Object> params) throws Exception {
		return selectSqlOne(sql, params);
	}
	@Override
	public List query(String hql) throws Exception {
		return select(hql);
	}
	@Override
	public List query(Class clazz) throws Exception {
		return select(clazz);
	}
	@Override
	public List query(Class clazz, Integer... ids) throws Exception {
		return select(clazz, ids);
	}
	@Override
	public List query(String hql, Object... params) throws Exception {
		return select(hql, params);
	}
	@Override
	public List query(String hql, Map<String, Object> params) throws Exception {
		return select(hql, params);
	}
	@Override
	public List query(String hql, int page, int rows, Object... params) throws Exception {
		return select(hql, page, rows, params);
	}
	@Override
	public List query(String hql, Object[] params, int page, int rows) throws Exception {
		return select(hql, page, rows, params);
	}
	@Override
	public List query(String hql, Map<String, Object> params, int page, int rows) throws Exception {
		return select(hql, params, page, rows);
	}
	@Override
	public List querySql(String sql) throws Exception {
		return selectSql(sql);
	}
	@Override
	public List querySql(String sql, Object... params) throws Exception {
		return selectSql(sql, params);
	}
	@Override
	public List querySql(String sql, int page, int rows) throws Exception {
		return selectSql(sql, page, rows);
	}
	@Override
	public List querySql(String sql, Map<String, Object> params) throws Exception {
		return selectSql(sql, params);
	}
	@Override
	public List querySql(String sql, int page, int rows, Object... params) throws Exception {
		return selectSql(sql, page, rows, params);
	}
	@Override
	public List querySql(String sql, Object[] params, int page, int rows) throws Exception {
		return selectSql(sql, page, rows, params);
	}

	@Override
	public List querySql(String sql, Map<String, Object> params, int page, int rows) throws Exception {
		return selectSql(sql, params, page, rows);
	}


	@Override
	public Timestamp timestamp(int month, int day, int hour) throws Exception {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, month);
		c.add(Calendar.DAY_OF_MONTH, day);
		c.add(Calendar.HOUR_OF_DAY, hour);
		Date d = c.getTime();
		return new Timestamp(d.getTime());
	}

	@Override
	public String getSql(String name) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getSql(String name, Object... params) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getSql(String name, Map params) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}


	
	
	

}
